package com.alex.security.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class HelloController {

    @GetMapping(value = {"/", "/index", "/home", "/welcome"})
    public String index(Model model) {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        SecurityContextHolder.getContextHolderStrategy();
        System.out.println(principal.getClass());
        System.out.println(principal);

        model.addAttribute("msg", "hello");
        model.addAttribute("user", principal);
        return "welcome";
    }

    @GetMapping("/userlogin")
    public String login() {
        return "login";
    }

    @GetMapping("/level1/{path}")
    public String level1(@PathVariable("path") String path) {
        return "pages/level1/" + path;
    }

    @GetMapping("/level2/{path}")
    public String level2(@PathVariable("path") String path) {
        return "pages/level2/" + path;
    }

    @GetMapping("/level3/{path}")
    public String level3(@PathVariable("path") String path) {
        return "pages/level3/" + path;
    }
}
